#include<bits/stdc++.h>
using namespace std;
int main()
{

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--)
    {
        int sum=0;
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        int d[100005],v[100005],a[100005];
        for(int i=0;i<n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(v[i]>V)
                sum++;
        }

        int p[100005];
        for(int i=0;i<m;i++)
            cin>>p[i];
         cout<<sum<<" "<<m-1<<endl;
    }

    return 0;
}
